package com.meixun.xuanke.handle.util;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

public class CourseUtil {
    static String[] weeks={"星期一","星期二","星期三","星期四","星期五","星期六","星期天"};
    public static String changeTimeText(String timeText,String timeJson){
        String text="";
        if(timeText.equals("null")||timeText.equals("")){
            try{

            }catch (Exception e){

            }
        }else {
            try {
                //3-8,3-9
                String[] dayStr = timeText.split(",");
                for (int i = 0; i <dayStr.length ; i++) {
                    String[] day = dayStr[i].split("-");
                    try {
                        int d=Integer.parseInt(day[0]);
                        int j=Integer.parseInt(day[1]);
                        if (d<weeks.length&d>0){
                            if (j==0){
                                text +=weeks[d-1]+"(全天) ";
                            }else{
                                text +=weeks[d-1]+"(第"+j+"节) ";
                            }
                        }


                    }catch (Exception e){

                    }
                }
            }catch (Exception e){

            }
        }

        return  text;
    }
    public static JSONArray getTimetable(List< HashMap<String,Object>> list){
        JSONArray array =new JSONArray();
        JSONObject[] days=new JSONObject[7];
        JSONArray[] arraylist= new JSONArray[7];
        for (int i = 0; i < 7; i++) {
            days[i]=new JSONObject();
            days[i].put("name",weeks[i]);
            days[i].put("key",(i+1));
            days[i].put("list",new JSONArray());
        }
        for (int i = 0; i <list.size() ; i++) {

        }
        return  array;
    }

    public static boolean isTimeConflict(String timeText,String myTimeText){
        boolean isConflict=false;
        try {
            //3-8,3-9
            int[][] times={};
            String[] dayStr = timeText.split(",");

            JSONObject timeAll= new JSONObject();
            for (int i = 0; i <dayStr.length ; i++) {
                String[] day = dayStr[i].split("-");
                try {
                    String d=day[0];
                    String j=day[1];
                    if(timeAll.containsKey(d)){
                        JSONObject dd=timeAll.getJSONObject(d);
                        dd.put(j,j);
                        timeAll.put(d,dd);
                    }else{
                        JSONObject dd=new JSONObject();
                        dd.put(j,j);
                        timeAll.put(d,dd);
                    }
                }catch (Exception e){

                }
            }

            dayStr = myTimeText.split(",");
            for (int i = 0; i <dayStr.length ; i++) {
                String[] day = dayStr[i].split("-");
                try {
                    String d=day[0];
                    String j=day[1];
                    if(timeAll.containsKey(d)){
                        JSONObject dd=timeAll.getJSONObject(d);
                        if(dd.containsKey("0")){
                            return  true;
                        }
                       if(dd.containsKey(j)){
                           return  true;
                       }
                    }
                }catch (Exception e){

                }
            }
        }catch (Exception e){

        }
        return  isConflict;
    }

 }
